%% This file writes data to be used by AMPL

% data_: the structure of data
% data_file: the name of the data file to be used by AMPL

%%
mod.field_names = fieldnames(data_);                  % Get the vector of parameter names 
mod.field_values = cell2mat(struct2cell(data_));      % Get the vector of parameter values 
mod.l_exo = length(mod.field_values);

temp.c=0;
temp.fid=fopen(data_file,'w');
%   c = c + AMPLcomment(fid,'Matlab generated AMPL data file\n');
%   c = c + AMPLcomment(fid,'');
%   c = c + AMPLcomment(fid,'For use with model uav_oa.mod');
%   c = c + AMPLcomment(fid,'');
for i = 1:mod.l_exo  
  % initial state
  temp.c = temp.c + AMPLscalar(temp.fid,mod.field_names{i},mod.field_values(i));
end

% completed writing file
fclose(temp.fid);
%sprintf('%d bytes written',temp.c)